package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author stay foolish
 * @description 行至水穷处, 坐看云起时
 * @date 2022/11/24 18:02:21
 * @description TODD
 */

public interface TripDao {
    /**
     * 查询所有行程信息
     * @return
     */
    @Select("select id,username,gender,idcard,from_address fromAddress,to_address toAddress,start_time startTime from tb_trip")
    List<Trip> findAllTrip();

    /**
     * 根据id查询行程信息
     * @return
     */
    @Select("select id,username,gender,idcard,from_address fromAddress,to_address toAddress,start_time startTime from tb_trip where id=#{id}")
    Trip findTripById(@Param("id") int id);

    /**
     * 根据id修改行程信息
     * @param trip
     */
    @Update("update tb_trip set username=#{username},from_address=#{fromAddress} where id=#{id} ")
    void updateTripById(Trip trip);

    /**
     * 根据id删除行程信息
     * @param id
     */
    @Delete("delete from tb_trip where id=#{id}")
    void deleteTripById(@Param("id") int id);

    /**
     * 添加用户行程
     * @param trip
     */
    @Insert("insert into tb_trip values(null,#{username},#{gender},#{idcard},null,null,null)")
    void addTrip(Trip trip);
}
